package com.linln.agent.member;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.linln.modules.system.domain.Area;
import com.linln.modules.system.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.linln.common.constant.AdminConst;
import com.linln.modules.member.domain.MemberAgent;
import com.linln.modules.member.domain.MemberInfo;
import com.linln.modules.member.domain.MemberOrder;
import com.linln.modules.member.service.MemberOrderService;

/**
 * @author hct
 * @date 2019/09/12
 */
@Controller
@RequestMapping("/agent/order")
public class AgentMemberOrderController {

    @Autowired
    private MemberOrderService memberOrderService;
    @Autowired
    AreaService areaService;
    /**
     * 列表页面
     */
    @GetMapping("/index")
    public String index(Model model, MemberOrder memberOrder,HttpServletRequest request) {
         MemberAgent agent=(MemberAgent)request.getSession().getAttribute(AdminConst.AGENT_AREA_NAME); 
 
        // 创建匹配器，进行动态查询匹配
        ExampleMatcher matcher = ExampleMatcher.matching();
        memberOrder.setArea(agent.getArea());
//        memberOrder.setPayStatus(1);
        // 获取数据列表
        Example<MemberOrder> example = Example.of(memberOrder, matcher);
        Page<MemberOrder> list = memberOrderService.getPageList(example);
        List<MemberOrder> content = list.getContent();
        if(content!=null && content.size()>0) {
        	Iterator<MemberOrder> it=list.iterator();
        	 
        	while(it.hasNext()) {
        	 
        	  if(it.next().getType().intValue()==5) { 
        	 
        	  it.remove();
        	 
        	 }
        	 
       }
      }
        // 封装数据
        model.addAttribute("list", content);
        model.addAttribute("page", list);
        model.addAttribute("payStatus",memberOrder.getPayStatus());
        return "/agent/member/order/index";
    }

     

    /**
     * 跳转到详细页面
     */
    @GetMapping("/detail/{id}")
    public String toDetail(@PathVariable("id") MemberOrder memberOrder, Model model) {
        model.addAttribute("order",memberOrder);
        return "/agent/member/order/detail";
    }

     
}